package com.example.administrator.sizhang_jineng;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.PopupWindow;

import java.util.ArrayList;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

public class Tu2 extends AppCompatActivity {

    private Toolbar mToolbar;
    private ExpandableListView mEl;
    private ArrayList<String> mGroup;
    private ArrayList<String> mItem;
    private ArrayList<String> mItem1;
    private ArrayList<ArrayList<String>> mTwoData;
    private Erladpater mEl1;
    private ListView mLv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tu2);
        erjileibiao();
        initView();

    }

    private void erjileibiao() {
        mGroup = new ArrayList<>();
        mGroup.add("朋友");
        mGroup.add("同学");
        mItem = new ArrayList<>();
        mItem.add("朋友");
        mItem.add("朋友");
        mItem.add("朋友");
        mItem1 = new ArrayList<String>();
        mItem1.add("同学");
        mItem1.add("同学");
        mItem1.add("同学");
        mTwoData = new ArrayList<>();
        mTwoData.add(mItem);
        mTwoData.add(mItem1);

    }

    private void initView() {
        mEl = (ExpandableListView) findViewById(R.id.el);
        mLv = (ListView) findViewById(R.id.lv);
        mEl = findViewById(R.id.el);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        registerForContextMenu(mEl);

        mToolbar.setTitle("标题");
        mToolbar.setLogo(R.drawable.ic_launcher_background);
        setSupportActionBar(mToolbar);
        //二级列表
        mEl1 = new Erladpater(mGroup, mTwoData);
        mEl.setAdapter(mEl1);
        mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case 1:

                        break;
                    case 2:
                        View inflate = LayoutInflater.from(Tu2.this).inflate(R.layout.item, null, false);
                        PopupWindow pp = new PopupWindow(inflate, ViewGroup.LayoutParams.WRAP_CONTENT, MATCH_PARENT);
                         pp.showAsDropDown(mToolbar);
                        break;
                }

                return false;
            }
        });



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(1, 1, 1, "ListView");
        menu.add(1, 2, 2, "GridView");
        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu, menu);
        super.onCreateContextMenu(menu, v, menuInfo);
    }

 /*   @Override
    public boolean onContextItemSelected(MenuItem item) {
        return super.onContextItemSelected(item);
        switch (item.getItemId()) {
            case R.id.item1:

                break;
        }
    }*/
}
